<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="d"></div>
</body>
</html>
<script>
    // 倒计时
    setInterval(function(){
        auto();
    },1000)

    // 倒计时函数
    function auto(){

        // 获取现在时间
        let now = new Date();
        // 获取未来时间
        let fur = new Date(2021,11,12);

        let timer = Math.ceil((fur - now) / 1000);
        // console.log(timer);

        // 换算（天，时，分，秒）
        // 天
        let day = parseInt(timer / (3600 * 24));
        // console.log(day);

        // 时
        let dayYu = (timer % (3600 * 24))
        let shi = parseInt(dayYu / (3600));
        // console.log(shi);

        // 分
        let fenYu = dayYu % (3600)
        let fen = parseInt(fenYu / (60))
        // console.log(fen);

        // 秒
        let miao = fenYu % 60;
        // console.log(miao);

        d.innerHTML = (ling(day) + "天" + ling(shi) + "时" + ling(fen) + "分" + ling(miao) + "秒")

    }

    function ling(num){
        if(num < 10){
            return "0" + num;
        }
        return num;
    }
</script>